#ifndef AIRCRAFTLIST_H
#define AIRCRAFTLIST_H

#include <QObject>
#include <QMap>
#include <QList>
#include <QString>
#include "aircraft.h"

namespace FsxSimConnect {

//! All aircrafts in a map, id to Aircraft *
/*! \sa Aircraft
    \author KWB */
// http://doc.qt.nokia.com/4.7-snapshot/qmap.html
class AircraftMap : public QMap<SIMCONNECT_OBJECT_ID, Aircraft>
{

private:
    mutable QMutex _mutex; /*!< Mutex for thread safety */
    //! Deep copy of the other aircrafts.
    /*! \param otherAircrafts waypoints to copy */
    void initByOtherList(const QList<Aircraft> otherAircrafts);
    //! Deep copy of the other aircrafts.
    /*! \param otherMap map to copy */
    void initByOtherMap(const AircraftMap &otherMap);
public:
    //! Default constructor.
    explicit AircraftMap();
    //! Constructor by other map, deep copy
    /*! \param otherMap */
    explicit AircraftMap(const AircraftMap &otherMap);
    //! Constructor by aircrafts, deep copy
    /*! \param otherAircrafts */
    explicit AircraftMap(const QList<Aircraft> &otherAircrafts);
    //! Assigment operator.
    /*! \param otherMap
        \return assigned map */
    AircraftMap &operator =(const AircraftMap &otherMap); // assignment operator
    //! Update given object, or create new one
    /*! \param id object id
        \param aircraftData data for the new aircraft object */
    void addOrUpdateById(const SIMCONNECT_OBJECT_ID id, const FSXAircraftStringAndMiscData aircraftData);
    //! Update given object, or create new one
    /*! \param id object id
        \param aircraftData data for the new aircraft object
        \param maxWaypoints max. waypoints considered
        \param timeFrameMs time frame considered */
    void addOrUpdateById(const SIMCONNECT_OBJECT_ID id, const FSXAircraftPositionAndSpeedData aircraftData, const int maxWaypoints, const qint64 timeFrameMs);
    //! Update given object, or create new one
    /*! \param id object id
        \param aircraftData data for the new aircraft object
        \param maxWaypoints max. waypoints considered
        \param timeFrameMs time frame considered */
    void addOrUpdateById(const SIMCONNECT_OBJECT_ID id, const FSXAircraftInstrumentationData aircraftData, const int maxWaypoints, const qint64 timeFrameMs);
    //! Update given object, or create new one
    /*! \param id object id
        \param aircraftData data for the new aircraft object */
    void addOrUpdateById(const SIMCONNECT_OBJECT_ID id, const FSXAircraftAvionicsData aircraftData);
    //! All aircrafts as JSON array.
    /*! \param level indention level
        \param parameter
        \return JSON string */
    QString toJsonArray(const int level, const JsonParameter &parameter) const;
    //! All aircrafts as HTML table.
    /*! \param level indention level
        \return HTML string */
    QString toHtmlTable(const int level) const;
};
} // namespace

#endif // AIRCRAFTLIST_H
